<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link href="../../../static/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" href="../../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../../static/js/jquery.cookie.min.js"></script>
	<script src="../../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/vui.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/datagrid.js"></script>
	<script type="text/javascript" src="../../../static/js/common.js"></script>
</head>
<body>
<div id="table"></div>

<script>
$(function(){
    $('#table').datagrid({
        url:app.BASE_API_URL+'role/userRolePage',
        simplePagination:true,
        queryParams:{userId:app.getRequestParams().id,limit:8},
        columns:[
            {field:'id',title:'<input type="checkbox" value="-1"/>',width:30,fixed:true,formatter:function (row) {
                if(row.roleId){
                    return '<input type="checkbox" checked="checked" value="'+row.id+'"/>';
				}else{
                    return '<input type="checkbox" value="'+row.id+'"/>';
				}
			}},
            {field:'name',title:'角色名称',width:100},
            {field:'code',title:'角色标识',width:100},
            {field:'comments',title:'角色描述',width:100}
        ]
    });

    app.getOkBtn().click(function(){
        var data = {id:app.getRequestParams().id};

        var index = 0;
        $('input[type="checkbox"]').each(function () {
            var checked = $(this).prop('checked');
            if( checked ){
                data['userRoles['+index+'].roleId'] = $(this).val();
                index++;
            }
        });

        app.request({
            url:'user/authority',
            data:data,
            success:app.actionSuccess_parent
        });


    });
});

</script>

</body>
</html>